<?php

namespace app\controllers;

use app\common\components\BaseWebController;
use Yii;
use yii\filters\AccessControl;
use yii\log\FileTarget;
use yii\web\Controller;
use yii\web\Response;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\ContactForm;

class ErrorController extends BaseWebController
{
    public function actionError(){
        $error = \Yii::$app->errorHandler->exception;
        $error_message = '';
        if($error){
            $file = $error->getFile();
            $message = $error->getMessage();
            $code = $error->getCode();
            $line = $error->getLine();
            $log = new FileTarget();
            $log->logFile = \Yii::$app->getRuntimePath() . '/logs/error.log';
            $error_message =$message . ' file:' . $file . ' line:' . $line . ' code:' . $code
                . ' url:' . $_SERVER['REQUEST_URI'] . '[POST_DATA:' . http_build_query($_POST) . ']';
            $log->messages[] = [
                $error_message,
                1,
                'application',
                microtime(true)
            ];
            $log->export();
            //todo : put in database
        }
        //$this->layouts = false;
        return $this->render('error', array('error_message' => $error_message));
    }
}
